/*
 * @Author: hh
 * @Date: 2025-09-02 15:10:53
 * @LastEditors: hh
 * @LastEditTime: 2025-09-02 15:27:46
 * @Description:
 */
import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { ApiProperty, ApiHideProperty } from '@nestjs/swagger';
import { Order } from './order.entity';
import { Book } from '../../book/entities/book.entity';

@Entity('order_items')
export class OrderItem {
  @PrimaryGeneratedColumn('uuid')
  @ApiProperty({ description: '订单项ID' })
  id: string;

  @ApiHideProperty()
  @ManyToOne(() => Order, (order) => order.items, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'order_id' })
  order: Order;

  @Column()
  @ApiProperty({ description: '订单ID' })
  order_id: string;

  @ApiHideProperty()
  @ManyToOne(() => Book, (book) => book.orderItems)
  @JoinColumn({ name: 'book_id' })
  book: Book;

  @Column()
  @ApiProperty({ description: '图书ID' })
  book_id: string;

  @Column('int')
  @ApiProperty({ description: '数量' })
  quantity: number;

  @Column('decimal', { precision: 10, scale: 2 })
  @ApiProperty({ description: '单价' })
  price: number;

  @Column('decimal', { precision: 10, scale: 2 })
  @ApiProperty({ description: '小计金额' })
  subtotal: number;
}
